package net.sudot.camel;

import org.apache.camel.Exchange;
import org.apache.camel.Expression;

import java.io.ByteArrayOutputStream;

/**
 * HTTP请求消息转换
 *
 * @author tangjialin on 2020-03-24.
 */
public class HttpRequestTransform implements Expression {
    @Override
    public <T> T evaluate(Exchange exchange, Class<T> type) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Object body = exchange.getIn().getBody();
        if (body != null) {
            JsonUtils.toJson(out, body);
        }
        return (T) out;
    }
}
